package com.example.demo3.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo3.entity.HwFacilityToilet;
import com.example.demo3.entity.User;
import com.example.demo3.service.HwFacilityToiletService;
import com.example.demo3.mapper.HwFacilityToiletMapper;
import com.example.demo3.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author Cp
 * @description 针对表【hw_facility_toilet(公厕)】的数据库操作Service实现
 * @createDate 2024-10-12 18:52:43
 */
@Service
public class HwFacilityToiletServiceImpl extends ServiceImpl<HwFacilityToiletMapper, HwFacilityToilet>
        implements HwFacilityToiletService {
    @Autowired
    HwFacilityToiletMapper hwFacilityToiletMapper;

    @Override
    public Result hwftlist(HwFacilityToilet hwFacilityToilet) {
        Page page=new Page(hwFacilityToilet.getPage(),hwFacilityToilet.getSize());
        QueryWrapper<HwFacilityToilet> queryWrapper=new QueryWrapper<HwFacilityToilet>();
        if(hwFacilityToilet.getName()!=null){
            queryWrapper.like("name",hwFacilityToilet.getName());
        }
        //查询分页数据，返回到Page对象中
        hwFacilityToiletMapper.selectPage(page,queryWrapper);
        //从Page对象中获取数据
        List<HwFacilityToilet> list=page.getRecords();
        long total=page.getTotal();
        //封装相应结果
        HashMap<String,Object> hashMap=new HashMap<>();
        hashMap.put("list",list);
        hashMap.put("total",total);
        return new Result(200,"查询成功",hashMap);
    }

    @Override
    public Result hwftAdd(HwFacilityToilet hwFacilityToilet) {
        int num =hwFacilityToiletMapper.insert(hwFacilityToilet);
        return new Result(200,"新增成功",num);
    }

    @Override
    public Result getName(String name) {
        QueryWrapper<HwFacilityToilet> queryWrapper=new QueryWrapper<HwFacilityToilet>();
        queryWrapper.eq("name",name);
        HwFacilityToilet hwFacilityToilet=hwFacilityToiletMapper.selectOne(queryWrapper);
        if(hwFacilityToilet!=null){
            return new Result(200,"名字重复",null);
        }else{
            return new Result(200,"名字不重复",null);
        }
    }

    @Override
    public Result hwftUpdate(HwFacilityToilet hwFacilityToilet) {
        int num =hwFacilityToiletMapper.updateById(hwFacilityToilet);
        return new Result(200,"修改成功",num);
    }

    @Override
    public Result hwftDelete(int id) {
        int num =hwFacilityToiletMapper.deleteById(id);
        return new Result(200,"删除成功",num);
    }


}




